package com.ykdl.member.kid.messagebox;

import java.util.HashMap;
import java.util.Map;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

import com.ykdl.member.kid.R;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.adapters.MyReanswerListAdapter;
import com.ykdl.member.kid.adapters.OfficialMessageAdapter;
import com.ykdl.member.kid.beans.OfficialMessageListBean;
import com.ykdl.member.kid.beans.PraiseListBean;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.member.kid.image.ImageLoader;
import com.ykdl.member.kid.messagebox.PraisesMeListActivity.getPraisesTag;
import com.ykdl.member.kid.widget.RefreshListView;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;

public class OfficialMessageActivity extends BaseScreen{
	private OfficialMessageAdapter adapter;
	private RefreshListView officialmessage_list;
	private String TAG = "OfficialMessageActivity";
	private String message_type_id = "1" ;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTopTitle("官方消息", 0, R.drawable.back_bg, new OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.e("ssss","setResultode---`11");
				setResult(-1);
				finish();
			}
		}, 0, 0, null, R.drawable.title_bg, false);
		setContent(R.layout.officialmessageactivity_xml);
		message_type_id = this.getIntent().getStringExtra(MyMessageAcivity.MESSAGE_TYPE_ID);
		if (message_type_id.equals("1")) {
			setTopNav("官方消息");
		}else {
			setTopNav("活动小精灵");
		}
		inint();
		}
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Log.e("ssss","setResultode---`11");
		setResult(-1);
		super.onBackPressed();
	}
	public void inint() {
		adapter = new OfficialMessageAdapter(this,TAG);
		officialmessage_list = (RefreshListView)findViewById(R.id.officialmessage_list);
		officialmessage_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				adapter.getItem(arg2);
				Log.e("----", "----------onItemClick-----arg2:"+arg2);
			}
		});
		officialmessage_list.setMoreButtoIsGon(true);
		getOfficialmessages();
	}
	public void getOfficialmessages() {
		showProgress("正在加载中,请稍等...");
		String  pageurl =KidConfig.GET_OFFICIAL_MESSAGES;
		Map<String,String> map = new HashMap<String, String>();
		map.put("start_id", "0");
		map.put("cursor", "0");
		map.put("count", "50");
		map.put("message_type_id", message_type_id);
		//message_type_id =1 为官方 2为活动
		HttpBaseRequest request  =  Wxxr.getInstance().getRequest(pageurl, map,"");
		 TaskManager.startHttpRequest(request, new getOfficialmessagesTag(),  OfficialMessageListBean.class);
	}
	
	class getOfficialmessagesTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "加载成功", 1).show();
			if (t instanceof OfficialMessageListBean) {
				OfficialMessageListBean bean = (OfficialMessageListBean)t;
				adapter.setlist(bean.getOfficialMessageBeanList());
				officialmessage_list.setAdapter(adapter);
				adapter.notifyDataSetChanged();
			}
			
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "加载失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	protected void onResume() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().setCurrentActivity(TAG);
		super.onResume();
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().pause(TAG);
		super.onPause();
	}
}